<template>
  <div>
    <now-loading v-if="loading" />
    <OffTheShelf v-else-if="!loading && mizone === null" />
    <div v-else class="micircle">
      <van-nav-bar class="navbar" title="米圈" left-arrow @click-left="router.replace({ name: 'recommend' })" />
      <div class="product-content">
        <van-image class="bg-img" :src="bgImg" />
        <div class="product">
          <div class="mizone-img">
            <van-image width="4.1rem" height="4.1rem" :src="mizone.img_url" />
          </div>
          <div class="product-detail">
            <div class="product-name">{{ mizone.product_name }}</div>
            <div class="hot">
              <div class="hot-num">
                <span>{{ mizone.heat }}热度</span><i></i><span>{{ mizone.join_num }}讨论</span>
              </div>
              <div class="attention" :class="{ active: isAttention }" @click="getAttention(mizone.product_id)">
                <span v-if="!isAttention"> + 关注</span>
                <span v-else>已关注</span>
              </div>
            </div>
          </div>

        </div>

      </div>
      <div class="more">
        <van-tabs :active="active" class="tab" color="#ff5528" title-active-color="#ff5528" line-width=".5rem"
          :border="true"  >
          <van-tab v-for="(item, index) in arr" :key="index" :title="item.title"
            :to="{ path: item.path, query: { id: route.query.id } }">
          </van-tab>
        </van-tabs>
        <div>
          <router-view></router-view>

        </div>


        <div>

        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import bgImg from '../../../assets/img/bgmi.jpeg'
import { getMizone } from '../../../api/find'
import { mizoneDetail, miTab } from '../../../typings'
import OffTheShelf from '../../../components/OffTheShelf.vue'
import NowLoading from '../../../components/NowLoading.vue'
import { onMounted, reactive, ref, watch } from 'vue'
import { useRoute } from 'vue-router';
import router from '../../../router'
const route = useRoute();
let arr = reactive<Array<miTab>>([
  {
    title: '推荐',
    path: "/micircle",
  },
  {
    title: '问大家',
    path: "/micircle/question_list",
  },
  {
    title: '测评',
    path: "/micircle/evaluate_list",
  },
  {
    title: '买家秀',
    path: "/micircle/buy_list",
  }
]);

const active = ref(null)
if(route.name=='buy_list'){
  active.value = 3
}
if(route.name=='question_list'){
  active.value = 1
}
if(route.name=='evaluate_list'){
  active.value = 2
}
if(route.name=='rcm_list'){
  active.value = 0
}


const mizone = ref<mizoneDetail>();
const loading = ref(true);
const isAttention = ref(false);
onMounted(async () => {
  let id = Number(route.query.id);
  console.log("此时的id=>", id);

  let res = await getMizone(id);
  mizone.value = res.data;
  getLoading();
})
const getAttention = (id) => {

  isAttention.value = !isAttention.value;
  if (isAttention.value) {
    console.log("关注了它=>", id);
  } else {
    console.log("取消关注它=>", id);
  }
}

const getLoading = () => {
  setTimeout(() => {
    loading.value = false;
  }, 1000);
}

</script>

<style lang="scss" scoped>
// .loading {
//   position: fixed;
//   left: 0;
//   bottom: 0;
//   top:0;
//   background-color:#fff;
//   z-index: 2;
//   width: 100vw;
// }
:deep(.van-nav-bar) {
  width: 100vw;
  background-color: transparent;
}

:deep(.van-nav-bar__title) {
  color: #fff;
  font-weight: bold;
}

:deep(.van-nav-bar__arrow) {
  color: #fff;
  font-size: 1.5rem;
}

:deep(.van-hairline--bottom:after) {
  border-bottom-width: 0;
}

.micircle {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 100vw;
  overflow: scroll;
  z-index: 9999;
  background-color: #fff;
}

.navbar {
  position: absolute;
  left: 0;
  top: 0;
}

.product-content {
  position: relative;
  width: 100vw;

  .bg-img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 13rem;
  }

  .product {
    width: 100%;
    position: absolute;
    top: 5rem;
    color: #fff;
    padding: 0rem 1rem;
    box-sizing: border-box;
    height: 4.2rem;

    display: flex;

    .mizone-img {
      background-color: #fff;
      padding: .1rem;
      border-radius: .2rem;
    }
  }
}

.product-detail {
  width: 100%;
  margin-left: 1rem;
  font-size: .8rem;

  .product-name {
    font-size: 1.17rem;
  }

  .hot {
    margin-top: .5rem;
    width: 100%;
    display: flex;
    justify-content: space-between;

    .hot-num {
      opacity: .5;
      margin-top: .35rem;
    }

    i {
      margin: 0rem .5rem;
      display: inline-block;
      height: .6rem;
      border-left: .1rem solid #fff;
    }

    .attention {
      padding: .4rem 1.2rem;
      border-radius: 9999rem;
      color: #000;
      opacity: 1;
      background-color: #fff;

      span {
        display: block;
        width: 4em;
        text-align: center;
      }

      &.active {
        background-color: #808187;
        color: #000;
      }
    }
  }
}


.more {
  position: absolute;
  top: 12rem;
  left: 0;
  width: 100vw;
  border-radius: .8rem .8rem 0rem 0rem;
  overflow: hidden;
  background-color: #fff;

  .tab {
    width: 100%;

    :deep(.van-tab__text) {
      font-size: 1.1rem;

    }
  }
}

.question {
  padding: 1rem;
  background-color: #f9f9f9;

  .top {
    background-color: #f9f9f9;

    .search {
      padding: 0;

      :deep(.van-search__content) {
        margin-bottom: 1rem;
        background-color: #f0f0f0;
        border-radius: 9999rem;
      }
    }

    .question-tab {
      display: flex;
      flex-wrap: wrap;

      li {
        background-color: #fff;
        padding: .4rem .8rem;
        margin: 0rem .5rem .5rem 0rem;
        font-size: .8rem;
        border-radius: 9999rem;
        font-weight: bold;
      }
    }
  }
}
</style>